﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class BallScriptL13 : MonoBehaviour
{
	public AudioSource dead;
	public GameObject ball;
	Rigidbody2D somebody;

	void Start()
	{
		somebody = GetComponent<Rigidbody2D>();
	}

	void OnCollisionEnter2D (Collision2D other)
	{

		if (other.gameObject.CompareTag ("Spikes")) 
		{
			dead.Play();
			ball.gameObject.GetComponent<SpriteRenderer> ().enabled = false;
			ball.gameObject.GetComponent<CircleCollider2D> ().enabled = false;
			somebody.constraints = RigidbodyConstraints2D.FreezeAll;
			StartCoroutine(InstantiateAfterDelay(1f));
		}
	}
	IEnumerator InstantiateAfterDelay(float delay)
	{
		yield return new WaitForSeconds (delay);
		SceneManager.LoadScene ("Level 13");
	}
}
